'''
Created on Dec 12, 2009

@author: grasping
'''
import numpy as np
from itertools import izip

def ndlerp(p1, p2, nSamples):
    if np.ndim(p1) != np.ndim(p2):
        raise ValueError, "NumDimensions for the endpoints isn't equal!"
    
    def innerVal(startVal, endVal, nSteps, curStep):
        return startVal+(endVal-startVal)*((1.0*curStep)/(nSteps-1))
    resultsArray = []
    for i in range(int(nSamples)):
        vals = [innerVal(dim_p1, dim_p2, nSamples, i) for dim_p1, dim_p2 in izip(p1,p2)]
        resultsArray.append(vals)
    return resultsArray